package getsmart.project.activity;

import getsmart.project.R;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class GaleriBelajar extends Activity
{
	ImageView imageHasil;
	TextView txtPenjelasanGambar;
    //---Daftar Gambar yang ingin Ditampilkan---
    Integer[] list_image = {
            R.drawable.anggur,
            R.drawable.apel,
            R.drawable.pisang,
            R.drawable.bunga,
            R.drawable.burung,
            R.drawable.gigi,
            R.drawable.hidung,
            R.drawable.jari,
            R.drawable.jeruk,
            R.drawable.jus,
            R.drawable.kuku,
            R.drawable.mangga,
            R.drawable.mata,
            R.drawable.mulut,
            R.drawable.tangan,
            R.drawable.telinga
    };
    String[] fruit_name = {"Indonesia: Anggur \nInggris: Apple",
    		"Indonesia: Apel \nInggris:Apple",
    		"Indonesia: Pisang \nInggris: Banana",
    		"Indonesia: Bunga \nInggris: Flower",
    		"Indonesia: Burung \nInggris: Bird",
    		"Indonesia: Gigi \nInggris: Tooth",
    		"Indonesia: Hidung \nInggris: Nose",
    		"Indonesia: Jari \nInggris: Finger",
    		"Indonesia: Jeruk \nInggris: Orange",
    		"Indonesia: Jus \nInggris: Juice",
    		"Indonesia: Kuku \nInggris: Fingernail",
    		"Indonesia: Mangga \nInggris: Manggoe",
    		"Indonesia: Mata \nInggris: Eyes",
    		"Indonesia: Mulut \nInggris: Mouth",
    		"Indonesia: Tangan \nInggris: Hand",
    		"Indonesia: Telinga \nInggris: Ear"};

    
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.galeri_belajar);
        
        imageHasil = (ImageView)findViewById(R.id.image1);
        txtPenjelasanGambar = (TextView)findViewById(R.id.txtPenjelasanGambar);
        Gallery gallery = (Gallery) findViewById(R.id.gallery1);
        
        gallery.setAdapter(new ImageAdapter(this));
        gallery.setOnItemClickListener(new OnItemClickListener()
        {
            public void onItemClick(AdapterView parent,View v, int position, long id)
            {
            	imageHasil.setImageResource(list_image[position]);
            	txtPenjelasanGambar.setText(fruit_name[position]);
                Toast.makeText(getBaseContext(),fruit_name[position],Toast.LENGTH_SHORT).show();
            }
        });
    }

    public class ImageAdapter extends BaseAdapter
    {
        private Context context;
        private int itemBackground;

        public ImageAdapter(Context c)
        {
            context = c;
            //---setting the style---
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
            itemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();
        }

        //---returns the number of images---
        public int getCount() {
            return list_image.length;
        }

        //---returns the ID of an item---
        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        //---returns an ImageView view---
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView = new ImageView(context);
            imageView.setImageResource(list_image[position]);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            imageView.setLayoutParams(new Gallery.LayoutParams(150, 150));
            imageView.setBackgroundResource(itemBackground);
            return imageView;
        }
    }
}